package com.atguigu.yygh.hosp.controller;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(description = "医院接口")
@RestController
@RequestMapping("/admin/hosp/hospital")
//@CrossOrigin
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    //查询医院详情数据
    @ApiOperation("查询医院详情")
    @GetMapping("show/{id}")
    public R showHosp(@PathVariable String id) {
        Map<String,Object> map = hospitalService.getHospById(id);
        return R.ok().data(map);
    }

    //更新医院上线状态 锁定解锁
    @ApiOperation("更新医院上线状态")
    @PutMapping("updateStatus/{id}/{status}")
    public R updateStatus(@PathVariable("id") String id,
                          @PathVariable("status") Integer status) {
        hospitalService.updateHospStatus(id,status);
        return R.ok();
    }

    //医院条件查询带分页
    @ApiOperation(value = "医院条件查询分页列表")
    @PostMapping("{page}/{limit}")
    public R pageHosp(@PathVariable Integer page,
                      @PathVariable Integer limit,
                      @RequestBody(required = false) HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> pageModel = hospitalService.selectPage(page,limit,hospitalQueryVo);

        return R.ok().data("pageModel",pageModel);
    }


}
